package com.bdqn.mapper.impl;

import com.bdqn.mapper.SysUserMapper;
import com.bdqn.pojo.SysUser;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service("sysUserMapper")
public class SysUserMapperImpl implements SysUserMapper {
    @Autowired //自动装配

    private SysUserMapper sysUserMapper;
    private SqlSessionTemplate sqlSession;

    public SqlSessionTemplate getSqlSession() {
        return sqlSession;
    }

    public void setSqlSession(SqlSessionTemplate sqlSession) {
        this.sqlSession = sqlSession;
    }

    @Override
    public List<SysUser> selectSysUserList(SysUser sysUser) {
        return sqlSession.selectList("com.bdqn.mapper.SysUserMapper.selectSysUserList", sysUser);
    }

    @Override
    public int adduser(SysUser sysUser) {
        try {
            return sysUserMapper.adduser(sysUser);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int delID(Integer id) {
        try {
            return sysUserMapper.delID(id);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int update(SysUser sysUser) {
        try {
            return sysUserMapper.update(sysUser);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int updatePassword(String password, Integer id) {
        try {
            return sysUserMapper.updatePassword(password, id);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

}

